﻿<%@ WebHandler Language="C#" Class="Otsql" %>
using System;
using System.Web;
using System.Collections.Generic;
using System.Data;

/// <summary>
/// 
/// </summary>
public class Otsql : MyAdmin_AjaxBase
{
    /// <summary>
    /// 处理程序请求
    /// </summary>
    /// <param name="context"></param>
    public override void ProcessRequest(HttpContext context)
    {
        try
        {
            Init();
            switch (operType)
            {
                case "ver_u_tx":
                    ver_u_outmoney();
                    break;
                case "delete_proble"://
                    delete_proble();
                    break;
                case "delete_link"://
                    delete_link();
                    break;
                case "delete_banner"://
                    delete_banner();
                    break;
                case "delNews"://
                    delNews();
                    break;
                case "delNewsForecast"://
                    delNewsForecast();
                    break;
                case "delGold"://
                    delGold();
                    break;
                case "delete_txord"://
                    delete_txord();
                    break;
                case "change_adminps"://
                    change_adminps();
                    break;
                case "updateUserMoney"://
                    updateUserMoney();
                    break;
                case "updateUserLevel"://
                    updateUserLevel();
                    break;
                default:
                    break;
            }
        }
        catch
        {
            alertmessage("操作异常");
        }
    }
    private void change_adminps()
    {
        string ps = ReadRequest.RequestString("ps");
        string jps = ReadRequest.RequestString("jps");
        Model.Manageadmin member = BLL.Manageadmin.GetOneBynickname("admin");
        if (member != null && member.uesrState > 0 && member.u_password == BLL.Security.MD5(jps.Trim()))
        {
            member.u_password = BLL.Security.MD5(ps);
            if (BLL.Manageadmin.Update(member) > 0)
            {
                alertmessageAndGoback("修改成功");
                return;
            }
            else
            {
                alertmessageAndGoback("修改失败");
                return;
            }
        }
        else
        {
            alertmessageAndGoback("修改失败");
            return;
        }
    }
    private void updateUserLevel()
    {
        long verid = ReadRequest.RequestLong("utxid");
        int userLevel = ReadRequest.RequestInt("UserLevel");
        if (verid > 0)
        {
            Model.CMember cm = BLL.CMember.GetModel(verid);
            cm.userLevel = userLevel;
            if (BLL.CMember.Update(cm) > 0)
            {
                returnmessage(true);
                return;
            }
        }
        returnmessage(false);
        return;
    }
    private void updateUserMoney()
    {
        long verid = ReadRequest.RequestLong("utxid");
        decimal UserMoney = ReadRequest.Requestdecimal("UserMoney");
        if (verid > 0)
        {
            Model.UsersAccount user_account = BLL.UsersAccount.GetModelByuser_id(verid);
            user_account.total = user_account.total + UserMoney;
            if (BLL.UsersAccount.Update(user_account) > 0)
            {
                returnmessage(true);
                return;
            }
        }
        returnmessage(false);
        return;
    }
    private void alertmessageAndGoback(string message)
    {
        System.Web.HttpContext.Current.Response.Write("<script type=\"text/javascript\">alert('" + message + "');history.go(-1);</script>");
    }
    private void alertmessageAndGo(string message, string url)
    {
        System.Web.HttpContext.Current.Response.Write("<script type=\"text/javascript\">alert('" + message + "');window.location.href = '" + url + "';</script>");
    }
    private void ver_u_outmoney()
    {
        if (loginUserInfo != null && loginUserInfo.Id > 0)
        {
            long verid = ReadRequest.RequestLong("utxid");
            if (verid > 0)
            {
                Model.SF_user_acc_cash acc_cash = BLL.SF_user_acc_cash.GetModel(verid);
                if (acc_cash != null && acc_cash.user_id > 0)
                {
                    Model.UsersAccount user_account = BLL.UsersAccount.GetModelByuser_id(acc_cash.user_id);
                    if (user_account.total >= acc_cash.total)
                    {
                        user_account.txTotal = user_account.txTotal + acc_cash.total;
                        acc_cash.s_status = 1;
                        if (BLL.UsersAccount.Update(user_account) > 0)
                        {
                            if (BLL.SF_user_acc_cash.Update(acc_cash) > 0)
                            {
                                returnmessage(true);
                                return;
                            }
                        }
                    }
                }

            }
        }
        returnmessage(false);
        return;
    }
    private void delete_banner()
    {
        if (BLL.SF_img_info.Delete(ReadRequest.RequestLong("long_eid")))
        {
            returnmessage(true);
            return;
        }
        returnmessage(false);
        return;
    }
    private void delete_link()
    {
        if (BLL.Link.Delete(ReadRequest.RequestLong("long_eid")))
        {
            returnmessage(true);
            return;
        }
        returnmessage(false);
        return;
    }
    private void delNews()
    {
        if (BLL.NewsSite.Delete(ReadRequest.RequestLong("long_eid")))
        {
            returnmessage(true);
            return;
        }
        returnmessage(false);
        return;
    }
    private void delNewsForecast()
    {
        if(BLL.ForecastPost.Delete(ReadRequest.RequestLong("long_eid")))
        {
            returnmessage(true);
            return;
        }
        returnmessage(false);
        return;
    }
    private void delGold()
    {
        if (BLL.GoldCode.Delete(ReadRequest.RequestLong("long_eid")))
        {
            returnmessage(true);
            return;
        }
        returnmessage(false);
        return;
    }
    private void delete_proble()
    {
        if (BLL.LotteryDes.Delete(ReadRequest.RequestLong("long_eid")))
        {
            returnmessage(true);
            return;
        }
        returnmessage(false);
        return;
    }
    private void delete_txord()
    {
        if (BLL.SF_user_acc_cash.Delete(ReadRequest.RequestLong("long_eid")))
        {
            returnmessage(true);
            return;
        }
        returnmessage(false);
        return;
    }
}